* Loading data
*****************

* use "/Users/damienbol/Dropbox/Expérience QC-SC/Données/Pooled3.dta", clear

set more off

* Recoding
**********

gen fav=fav2
replace fav=fav1 if exp==1
replace age=age-2 if sco==1

drop if age==7
drop if education==7

drop if polint==6
drop if moreno==7

gen univ=0
replace univ=1 if education==4

gen id=0
replace id=1 if moreno==1
replace id=1 if moreno==2

replace genre=0 if genre==2
replace genre=1 if genre==1

replace polint=5-polint

* Descriptives
**************

* Table 1

bysort sco: tab age
bysort sco: tab genre
bysort sco: tab univ
bysort sco: tab polint
bysort sco: tab id

bysort sco: sum fav, det

* Figure 1

label define exp 1"Support for status-quo" 2"Support for democratic reform" 3"Support for regionalist reform"
label value exp exp

stripplot fav if sco==0, bar iqr over(exp) color(none) graphregion(color(white)) ytitle("") xlabel(0(10)100) xtitle("") title("Quebec", color(black)) scheme(s2mono)
graph save "/Users/damienbol/Desktop/qc.gph", replace

stripplot fav if sco==1, bar iqr over(exp) boffset() color(none) graphregion(color(white)) ytitle("") xlabel(0(10)100) xtitle("") title("Scotland", color(black)) scheme(s2mono)
graph save "/Users/damienbol/Desktop/sco.gph", replace

graph combine "/Users/damienbol/Desktop/qc.gph" "/Users/damienbol/Desktop/sco.gph", row(3) graphregion(color(white))

bysort sco: ttest fav if exp!=1, by(exp)
bysort exp: ttest fav, by(sco)

bysort sco: sum fav if exp==1, det
bysort sco:sum fav if exp==2, det
bysort sco:sum fav if exp==3, det

* Analyses
**********

* Diagnostics: homoskedasticy

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
hettest

* Diagnostics: Conditional mean assumption

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
ovtest

* Diagnostics: Linearity

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
rvfplot, graphregion(color(white)) scheme(s2mono)

* Regression table 

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
outreg2 using "/Users/damienbol/Desktop/regression.doc", se dec(2) alpha(0.01, 0.05, 0.1) replace

* Test H1

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, at(exp=1) at(exp=2) at(exp=3) atmeans pwcompare(effects)

* Test H2

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(polint) at(exp=2) atmeans

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(polint) at(exp=3) atmeans

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(polint) at(exp=1) atmeans


quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(genre) at(exp=3) atmeans

* Test H3a

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(sco) at(exp=2) atmeans

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(sco) at(exp=3) atmeans

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(sco) at(exp=1) atmeans 

* Test H3b

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(id) at(exp=2 sco=0) at(exp=2 sco=1) vsquish pwcompare(effects)

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(id) at(exp=3 sco=0) at(exp=3 sco=1) vsquish pwcompare(effects)

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco
margins, dydx(id) at(exp=1 sco=0) at(exp=1 sco=1) vsquish pwcompare(effects)

* Robustness
************

gen fav_dum=0
replace fav_dum=1 if fav>50

logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
outreg2 using "/Users/damienbol/Desktop/regression.doc", se dec(2) alpha(0.01, 0.05, 0.1) append

* Test H1

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, at(exp=1) at(exp=2) at(exp=3) atmeans pwcompare(effects)

* Test H2

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(polint) at(exp=2) atmeans

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(polint) at(exp=3) atmeans

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(polint) at(exp=1) atmeans

* Test H3a

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(sco) at(exp=2) atmeans

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(sco) at(exp=3) atmeans

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(sco) at(exp=1) atmeans


* Test H3b

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(id) at(exp=2 sco=0) at(exp=2 sco=1) vsquish pwcompare(effects)

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(id) at(exp=3 sco=0) at(exp=3 sco=1) vsquish pwcompare(effects)

quietly logit fav_dum c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
margins, dydx(id) at(exp=1 sco=0) at(exp=1 sco=1) vsquish pwcompare(effects)


* Figure: Political interest
****************************

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
quietly margins exp, over(polint) at(sco=0) atmeans
marginsplot, horizontal graphregion(color(white)) scheme(s2mono) xlabel(30 (10) 80) level(95) plot1opts(lcolor(white)) xtitle("") ytitle("") bydimension(exp) ylabel(0 "Not interested in politics at all" 1"Not interested in politics" 2"Neither interested, nor not interested" 3"Interested in politics" 4"Very interested in politics")

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
quietly margins exp, over(polint) at(sco=1) atmeans
marginsplot, horizontal graphregion(color(white)) scheme(s2mono) xlabel(30 (10) 80) level(95) plot1opts(lcolor(white)) xtitle("") ytitle("") bydimension(exp) ylabel(0 "Not interested in politics at all" 1"Not interested in politics" 2"Neither interested, nor not interested" 3"Interested in politics" 4"Very interested in politics")

* Figure: Regionalist ID
*************************

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
quietly margins exp, at(id=0 sco=0) at(id=1 sco=0) atmeans
marginsplot, horizontal graphregion(color(white)) scheme(s2mono) xlabel(30 (10) 80) level(95) plot1opts(lcolor(white)) xtitle("") ytitle("") bydimension(exp) ylabel(1 "No regional identity" 2"Regional identity") graphregion(col(3))

quietly reg fav c.age##i.exp##i.sco i.univ##i.exp##i.sco i.genre##i.exp##i.sco c.polint##i.exp##i.sco i.id##i.exp##i.sco, robust
quietly margins exp, at(id=0 sco=1) at(id=1 sco=1) atmeans
marginsplot, horizontal graphregion(color(white)) scheme(s2mono) xlabel(30 (10) 80) level(95) plot1opts(lcolor(white)) xtitle("") ytitle("") bydimension(exp) ylabel(1 "No regional identity" 2"Regional identity") graphregion(col(3))


* Balance test
**************

mlogit exp age univ genre polint id i.sco
outreg2 using "/Users/damienbol/Desktop/balance.doc", se dec(2) alpha(0.01, 0.05) replace


